//
//  SetPassController.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/1/8.
//  Copyright © 2016年 game. All rights reserved.
//

#import "SetPassController.h"
#import "PersonNavView.h"
#import "Manager.h"
#import "UINavigationController+FDFullscreenPopGesture.h"
@interface SetPassController ()
{

    UIView *_texetView;
    UITextField *_passText;
    UITextField *_surePass;
}
@end

@implementation SetPassController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    self.app.myTabBar.tabBar.hidden = YES;
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
    [self NavView];

}
#pragma mark--自定义导航
-(void)NavView{

    PersonNavView *naview = [[PersonNavView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    naview.title.text = @"忘记密码";
    naview.BackToFatherView = ^{
        
        if (_passText.text.length==0&&_surePass.text.length==0) {
            [self.navigationController popViewControllerAnimated:NO];
        }else{
            
            UIAlertController *alert = [self ShowAlertWhthTitle:@"提示" Message:@"您确定放弃此次的修改" CancelButtonTitle:@"取消"];
            UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [self.navigationController popViewControllerAnimated:NO];
            }];
            
            [alert addAction:cancel];
        }
    };
    [self.view addSubview:naview];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self CrearTextField];
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(keBoyTap)];
    [self.view addGestureRecognizer:tap];
}

-(void)keBoyTap{
    [[[UIApplication sharedApplication]keyWindow]endEditing:YES];

}
-(void)CrearTextField{
    _texetView =[self Linview:CGRectMake(-1, 84, SCREEN_WIDTH+2, screen_height*0.2) BackgroundColor:[UIColor whiteColor] AddView:self.view];
    _texetView.backgroundColor =  [UIColor whiteColor];
    _texetView.layer.borderWidth = 1;
    _texetView.layer.borderColor = RGBA(225, 225, 225, 1).CGColor;
    _texetView.layer.masksToBounds = YES;
    
    [self Linview:CGRectMake(13, H(_texetView)/2, SCREEN_WIDTH-30, 1) BackgroundColor:RGBA(225, 225, 225, 1) AddView:_texetView];
    
    //设置密码
    _passText= [self CrectTextFieldWhithRect:CGRectMake(20, 4, SCREEN_WIDTH-40, H(_texetView)/2-5) Placeholder: @"请输入6-18位字母数字组合密码" FatherView:_texetView];
    _passText.secureTextEntry = YES;

    //确认密码
    _surePass = [self CrectTextFieldWhithRect:CGRectMake(20,Height(_passText)+4, SCREEN_WIDTH-40, H(_passText)) Placeholder:@"请确认密码" FatherView:_texetView];
    _surePass.secureTextEntry = YES;

    UIButton *nextBnt = [self CreatBntAddView:self.view WhithRect:CGRectMake(X(_passText),Height(_texetView)+15, SCREEN_WIDTH-X(_passText)*2, 40) AndType:UIButtonTypeSystem AndBntImgName:@"aiksdn," AndTitle:@"确认修改" Font:SCREEN_WIDTH*0.07];
    radius(nextBnt, 3);
    nextBnt.backgroundColor = mainColor;
    [nextBnt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [nextBnt addTarget:self action:@selector(nextCtl) forControlEvents:UIControlEventTouchUpInside];
}

-(void)nextCtl{
    
    if (_passText.text.length==0||_surePass.text.length==0) {
        [Manager GetHudWhithText:@"请正确填写信息" AndFatherView:self.view];
    }else if (![_passText.text isEqualToString:_surePass.text]) {
            [Manager GetHudWhithText:@"两次密码不一致" AndFatherView:self.view];
    }else{
        
        
        
        NSDictionary *dic = @{@"mobile":self.mobile,
                              @"sms_code":self.smsCode,
                              @"new_password":_passText.text,
                              @"new_password2":_surePass.text,
                              };
        [[Manager sharedManager]ResponseWhithURL:PassWordForget AndParameter:dic AndCompletionType:^(id responseObject, DIEError *error) {

            if ([responseObject[@"status"]isEqualToString:@"SUCCESS"]) {
                
                [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
               
            }else{
                
                [Manager GetHudWhithText:responseObject[@"message"] AndFatherView:self.view];
                
            }

        }];

    }
    
}
@end
